package com.woniuxy.productServer.controller;


import cn.hutool.core.bean.BeanUtil;
import com.github.pagehelper.PageInfo;
import com.woniuxy.commons.util.Result;
import com.woniuxy.productServer.form.movieSession.MovieSessionAddForm;
import com.woniuxy.productServer.form.movieSession.MovieSessionChangeForm;
import com.woniuxy.productServer.form.movieSession.MovieSessionLoadForm;
import com.woniuxy.productServer.model.MovieSession;
import com.woniuxy.productServer.param.movieSession.MovieSessionAddParam;
import com.woniuxy.productServer.param.movieSession.MovieSessionChangeParam;
import com.woniuxy.productServer.param.movieSession.MovieSessionParam;
import com.woniuxy.productServer.service.MovieSessionService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 杜岷芫
 * @since 2024年03月20日
 */
@RestController
@RequestMapping("/movieSession")
@Api(tags = "电影排场")
public class MovieSessionController {
    @Autowired
    private MovieSessionService movieSessionService;
    @PostMapping("/add.api")
    @ApiOperation("新增排场")
    public Result add(@RequestBody List<MovieSessionAddForm> forms) throws Exception {
        movieSessionService.add(forms);
        return Result.getResult().setMsg("新增成功");
    }

    @PostMapping("/load")
    @ApiOperation("查询排场")
    public Result load (@RequestBody MovieSessionLoadForm form){
        MovieSessionParam param = BeanUtil.toBean(form, MovieSessionParam.class);
        PageInfo<MovieSession> pageInfo= movieSessionService.load(param);
        return Result.getPageInfoResult(MovieSession.class).setMsg("查询场次成功").setData(null);
    }

    @PostMapping("/change.api")
    @ApiOperation("上下架")
    public Result change(@RequestBody MovieSessionChangeForm form) throws Exception {
        MovieSessionChangeParam param = BeanUtil.toBean(form, MovieSessionChangeParam.class);
        movieSessionService.change(param);
        return Result.getResult().setMsg("修改成功");
    }


    @PostMapping("/loadMovieSessionById/{id}")
    public Result<MovieSession> loadMovieSessionById(@PathVariable("id") Integer id) throws Exception {
        MovieSession movieSession = movieSessionService.getById(id);
        return Result.getResult(MovieSession.class).setMsg("成功").setData(movieSession);
    }


    @PostMapping("/test")
    public void test() throws Exception {
        movieSessionService.test();
    }
}

